import java.awt.*; import java.awt.event.*; class MyFrame extends Frame implements ActionListener { TextField t1,t2; Button b1,b2,b3,b4; TextArea txt; public MyFrame() { setLayout(new FlowLayout()); t1=new TextField(10); t2=new TextField(10); b1=new Button("+"); b2=new Button("-"); b3=new Button("x"); b4=new Button("/"); txt=new TextArea(5,20); add(t1); add(t2); add(b1); b1.addActionListener(this); add(b2); b2.addActionListener(this); add(b3); b3.addActionListener(this); add(b4); b4.addActionListener(this); add(txt); } public void actionPerformed(ActionEvent e) { String n1=t1.getText(); String n2=t2.getText(); Double d1=Double.parseDouble(n1); Double d2=Double.parseDouble(n2); double n=0; String op=e.getActionCommand(); if(op.equals("+")) n=d1+d2; if(op.equals("-")) n=d1-d2; if(op.equals("x")) n=d1*d2; if(op.equals("/")) n=d1/d2; String rs=String.valueOf(n); String exp=n1+" "+op+" "+n2+"="+rs; txt.insert(exp+"\n",0); } } class demo { public static void main(String args[]) { MyFrame frm=new MyFrame(); frm.setVisible(true); frm.setSize(400,400); } }